10 COMMON RH: IF RH=0 THEN SYSTEM
15 CLEAR: ON ERROR GOTO 340
20 SCREEN 0: WIDTH 80: COLOR 14,1,1: KEY OFF: CLS
25 PRINT "SOUNDEX Code Calculator": PRINT
30 PRINT "Enter any word or phrase, and this program"
40 PRINT "will calculate its SOUNDEX code for you."
50 PRINT "Press ESC to return to the main menu ...": PRINT
60 KEY (17) ON: KEY 17, CHR$(0)+CHR$(1): ON KEY (17) GOSUB 300
100 LINE INPUT "Enter any word or phrase: "; WORD$
110 GOSUB 170: PRINT: PRINT "The SOUNDEX code for ";
120 PRINT "the phrase ";CHR$(34);WORD$;CHR$(34);
130 PRINT " is ";CODE$;".": PRINT: GOTO 100
140 '
150 ' Calculate Soundex Code CODE$ for Word in WORD$
160 '
170 CODE$="": DIGIT$="": LAST$=""
180 FOR A=1 TO LEN(WORD$): LETTER$=MID$(WORD$,A,1)
190 IF LETTER$>"Z" THEN LETTER$=CHR$(ASC(LETTER$)-32)
200 IF INSTR("BFPV",LETTER$) THEN DIGIT$="1"
210 IF INSTR("CGJKQSXZ",LETTER$) THEN DIGIT$="2"
220 IF INSTR("DT",LETTER$) THEN DIGIT$="3"
230 IF INSTR("L",LETTER$) THEN DIGIT$="4"
240 IF INSTR("MN",LETTER$) THEN DIGIT$="5"
250 IF INSTR("R",LETTER$) THEN DIGIT$="6"
260 IF DIGIT$=LAST$ THEN 280
270 CODE$=CODE$+DIGIT$: LAST$=DIGIT$
280 NEXT A: RETURN
300 CLS: LOCATE 12,28: PRINT "One moment please...": RUN "menu"
310 '
320 'Error Trap
330 '
340 RESUME NEXT
